package com.qianxx.component.activity.recycleview.water_fall_flow;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.Toast;

import com.qianxx.component.R;
import com.qianxx.component.activity.base.BaseActivity;
import com.qianxx.component.tool.MyItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WaterFallFlowActivity extends BaseActivity {
    @BindView(R.id.recycler_view)
    RecyclerView recycler_view;

    List<Integer> list = new ArrayList<>();
    WaterFallFlowAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_water_fall_flow);
        ButterKnife.bind(this);

        initData();
        initView();
    }

    private void initView() {
        recycler_view.setLayoutManager(new StaggeredGridLayoutManager(2,
                StaggeredGridLayoutManager.VERTICAL));
        adapter = new WaterFallFlowAdapter(this,list);
        recycler_view.setAdapter(adapter);
        recycler_view.addItemDecoration(new MyItemDecoration(3));
        adapter.setOnItemClickListener(new WaterFallFlowAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(View view, int position) {
                Toast.makeText(getApplicationContext(), position + "",
                        Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initData() {
        list.add(R.drawable.p1);
        list.add(R.drawable.p2);
        list.add(R.drawable.p3);
        list.add(R.drawable.p4);
        list.add(R.drawable.p5);
        list.add(R.drawable.p6);
        list.add(R.drawable.p7);
        list.add(R.drawable.p8);
        list.add(R.drawable.p1);
        list.add(R.drawable.p2);
        list.add(R.drawable.p3);
        list.add(R.drawable.p4);
        list.add(R.drawable.p5);
        list.add(R.drawable.p6);
        list.add(R.drawable.p7);
        list.add(R.drawable.p8);
    }

    @Override
    public String setTitle() {
        return "WaterFallFlow";
    }
}
